﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HandyControl.Controls;
using Stylet;
namespace ImgConventICO.Models
{
    internal class BaiduImageModel : PropertyChangedBase, IDataErrorInfo
    {



        private string _name;
        private int _age;

        public string Name
        {
            get => _name;
            set
            {
                if (string.IsNullOrWhiteSpace(value))
                {
                    throw new ArgumentException("名字不能为空。");
                }
                _name = value;
            }
        }

        public int Age
        {
            get => _age;
            set
            {
                if (value < 1 || value > 120)
                {
                    throw new ArgumentException("年龄必须介于1和120之间。");
                }
                _age = value;
            }
        }

        // IDataErrorInfo implementation
        public string Error
        {
            get
            {
                // 返回与整个对象相关的错误信息
                if (string.IsNullOrWhiteSpace(Name) || Age < 0 || Age > 120)
                {
                    return "There are validation errors.";
                }
                return null;
            }
        }

        public string this[string columnName]
        {
            get
            {
                switch (columnName)
                {
                    case nameof(Name):
                        if (string.IsNullOrWhiteSpace(Name))
                        {
                            return "Name cannot be empty.";
                        }
                        break;

                    case nameof(Age):
                        if (Age < 0 || Age > 120)
                        {
                            return "Age must be between 0 and 120.";
                        }
                        break;
                }
                return null;
            }
        }
    }

}

